//
//  FBtModel.h
//  JwPack
//
//  Created by 陈警卫 on 2025/7/21.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>

#import "FBtConfig.h"

// 蓝牙状态
typedef NS_ENUM(NSUInteger , FBtState) {
    FBtStateDefault = 0,  // 默认
    FBtStateUnsupported,  // 不支持
    FBtStateUnauthorized, // 无授权
    FBtStatePoweredOff,   // 关闭
    FBtStatePoweredOn,    // 开启
};

// 外设状态
typedef NS_ENUM(NSUInteger , FBtPeriState) {
    FBtPeriStateDefault = 0,    // 默认
    FBtPeriStateScaning,        // 正在扫描(默认自动连接)
    FBtPeriStateScaned,         // 扫描成功
    FBtPeriStateConnecting,     // 正在连接
    FBtPeriStateConnected,      // 连接成功
    FBtPeriStateConnectFail,    // 连接失败
    FBtPeriStateNotifyed,       // 订阅成功
    FBtPeriStateDisconnect,     // 设备断开
    FBtPeriStateUserDisconnect, // 用户断开
};

// 外设状态
typedef NS_ENUM(NSUInteger , FBtPeriDataSate) {
    FBtPeriDataSateDefault = 0,    // 默认
    FBtPeriDataSateHandshaked,     // 握手成功
};


NS_ASSUME_NONNULL_BEGIN

@interface FBtModel : NSObject

@end


@interface FBtPeriModel : NSObject

/// 状态
@property (nonatomic, assign) FBtPeriState state;

/// 握手状态
@property (nonatomic, assign) FBtPeriDataSate dataState;

// 扫描连接过滤

@property (nonatomic, strong) NSString *connectUuid;
@property (nonatomic, strong) NSString *connectName;

/// 通讯服务UUID数组
@property (nonatomic, strong) NSArray<CBUUID *> *serviceUUIDs;
/// 写入特征UUID数组
@property (nonatomic, strong) NSArray<CBUUID *> *writeUUIDs;
/// 订阅特征UUID数组
@property (nonatomic, strong) NSArray<CBUUID *> *notifUUIDs;

// 设置

@property (nonatomic, assign) BOOL retrieve; // 是否通过恢复连接
@property (nonatomic, assign) CGFloat timeout; // 连接超时时间(0:不设置超时)

// 连接后信息

@property (nonatomic, strong) CBPeripheral *peri;
@property (nonatomic, strong) CBCharacteristic *writeChara;
@property (nonatomic, strong) CBCharacteristic *notifChara;

@property (nonatomic, strong) NSDictionary *advDict;
@property (nonatomic, strong) NSNumber *rssi;
@property (nonatomic, strong) NSString *mac;

/// 外设Uuid
- (NSString *)periUuid;
/// 外设name
- (NSString *)periName;
/// 外设制造商数据
- (NSData *)periMaferData;


// timer

@property (nonatomic, strong, nullable) NSTimer *timer;
@property (nonatomic, copy) void(^didTimerAction)(NSError *error); // 连接超时回调

- (void)startTimer;
- (void)endTimer;


@end


NS_ASSUME_NONNULL_END
